
package com.bstek.urule.model.rule.lhs;

import com.bstek.urule.runtime.rete.EvaluationContext;

import java.util.List;

/**
 * @author Jacky.gao
 * @since 2016年8月15日
 */
public class NamedCriteria extends BaseCriterion implements BaseCriteria {
    private String referenceName;
    private String variableCategory;
    private CriteriaUnit unit;
    private String id;

    @Override
    public EvaluateResponse evaluate(EvaluationContext context, Object obj, List<Object> allMatchedObjects) {
        EvaluateResponse response = unit.evaluate(context, obj, allMatchedObjects);
        return response;
    }

    public String getReferenceName() {
        return referenceName;
    }

    public void setReferenceName(String referenceName) {
        this.referenceName = referenceName;
    }

    public String getVariableCategory() {
        return variableCategory;
    }

    public void setVariableCategory(String variableCategory) {
        this.variableCategory = variableCategory;
    }

    public CriteriaUnit getUnit() {
        return unit;
    }

    public void setUnit(CriteriaUnit unit) {
        this.unit = unit;
    }

    @Override
    public String getId() {
        if (id == null) {
            StringBuffer sb = new StringBuffer();
            sb.append(referenceName + ":" + variableCategory + "(");
            sb.append(unit.getId());
            sb.append(")");
            id = sb.toString();
        }
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
